Skip to content

Commit

Permalink
Uses default error key if specified key doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Mar 6, 2017
1 parent f0f4e9e commit b06dd50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Expand Up @@ -26,7 +26,6 @@
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.ValidationAware;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.TextParseUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -38,7 +37,6 @@
import org.apache.struts2.util.ContentTypeMatcher;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.NumberFormat;
import java.util.*;

Expand Down Expand Up @@ -258,11 +256,16 @@ public String intercept(ActionInvocation invocation) throws Exception {

MultiPartRequestWrapper multiWrapper = (MultiPartRequestWrapper) request;

if (multiWrapper.hasErrors()) {
if (multiWrapper.hasErrors() && validation != null) {
TextProvider textProvider = getTextProvider(action);
for (LocalizedMessage error : multiWrapper.getErrors()) {
if (validation != null) {
validation.addActionError(LocalizedTextUtil.findText(error.getClazz(), error.getTextKey(), ActionContext.getContext().getLocale(), error.getDefaultMessage(), error.getArgs()));
String errorMessage;
if (textProvider.hasKey(error.getTextKey())) {
errorMessage = textProvider.getText(error.getTextKey(), Arrays.asList(error.getArgs()));
} else {
errorMessage = textProvider.getText("struts.messages.error.uploading", error.getDefaultMessage());
}
validation.addActionError(errorMessage);
}
}

Expand Down
Expand Up @@ -231,7 +231,7 @@ public void testInvalidContentTypeMultipartRequest() throws Exception {
req.setContentType("text/xml"); // not a multipart contentype
req.addHeader("Content-type", "multipart/form-data");

MyFileupAction action = new MyFileupAction();
MyFileupAction action = container.inject(MyFileupAction.class);
MockActionInvocation mai = new MockActionInvocation();
mai.setAction(action);
mai.setResultCode("success");
Expand All @@ -252,7 +252,7 @@ public void testNoContentMultipartRequest() throws Exception {
req.addHeader("Content-type", "multipart/form-data");
req.setContent(null); // there is no content

MyFileupAction action = new MyFileupAction();
MyFileupAction action = container.inject(MyFileupAction.class);
MockActionInvocation mai = new MockActionInvocation();
mai.setAction(action);
mai.setResultCode("success");
Expand Down Expand Up @@ -386,7 +386,7 @@ public void testMultipartRequestLocalizedError() throws Exception {
"-----1234--\r\n");
req.setContent(content.getBytes("US-ASCII"));

MyFileupAction action = new MyFileupAction();
MyFileupAction action = container.inject(MyFileupAction.class);

MockActionInvocation mai = new MockActionInvocation();
mai.setAction(action);
Expand Down Expand Up @@ -453,7 +453,7 @@ protected void tearDown() throws Exception {
super.tearDown();
}

private class MyFileupAction extends ActionSupport {
public static class MyFileupAction extends ActionSupport {

private static final long serialVersionUID = 6255238895447968889L;

Expand Down

0 comments on commit b06dd50

Please sign in to comment.